<?php

// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// [ 应用入口文件 ]
// 定义应用目录

try{
    define('APP_PATH', __DIR__ . '/../application/');
    // 加载框架引导文件
    require __DIR__ . '/../thinkphp/start.php';

}catch (\Exception $e){

    $content['msg'] = $e->getMessage();
    $content['file'] = $e->getFile();
    $content['line'] = $e->getLine();
    $content['detail'] = $e->getTrace();
    if(config('app_debug') == true){
        echo '<pre>';
        print_r($content);die;
    }
    $dir = '../runtime/log/error/'.date('Y').'/'.date('m').'/';
    $url = $dir.date('d').'.log';
    $content_detail = '### '.date('Y-m-d H:i:s').'  @@@  '.json_encode($content, JSON_UNESCAPED_UNICODE)."  @@\n\r";
    if (!is_dir($dir)){
        mkdir($dir, 0777, true); // 使用最大权限0777创建文件
    }

    file_put_contents($url, $content_detail, FILE_APPEND);

    if (!is_writable($url)){
        chmod($url, 0777); // 如果无权限，则修改为0777最大权限
    }
}


